package entity

import "time"

type OrderLog struct {
	ID           int       `gorm:"column:id;PRIMARY_KEY"`
	OperatorId   int       `gorm:"column:operator_id"`
	OperatorName string    `gorm:"column:operator_name"`
	OperatorType int       `gorm:"column:operator_type"`
	OrderId      int       `gorm:"column:order_id"`
	State        int       `gorm:"column:state"`
	Remark       string    `gorm:"column:remark"`
	CreatedAt    time.Time `gorm:"column:created_at"`
	Attr         string    `gorm:"column:attr"`
}

func (OrderLog) TableName() string {
	return "l_order_log"
}

func NewFailedOrderLogWithOrder(remark string, order *Order, attr string) *OrderLog {
	l := new(OrderLog)
	if order != nil {
		l.OperatorId = order.UserId
		l.OrderId = order.ID
	}
	l.OperatorName = ""
	l.State = -3
	l.Remark = remark
	l.OperatorType = 1
	if attr != "" {
		l.Attr = attr
	}
	return l
}

func NewStateLogWithOrder(order *Order, stat int, remark string, attr string) *OrderLog {
	l := new(OrderLog)
	if order != nil {
		l.OperatorId = order.UserId
		l.OrderId = order.ID
	}
	l.OperatorName = ""
	l.State = stat
	if remark != "" {
		l.Remark = remark
	}
	l.OperatorType = 1
	if attr != "" {
		l.Attr = attr
	}
	return l
}
